package zjl.graph;

public class Vertex implements BaseVertex, Comparable<Vertex> {

    private static int currentVertexId = 0;  // Uniquely identify each vertex

    // 节点标识
    private int id;

    // 节点权重值
    private double weight;

    public Vertex() {
        this.id = currentVertexId;
        currentVertexId++;
    }

    @Override
    public int getId() {
        return id;
    }

    @Override
    public double getWeight() {
        return weight;
    }

    @Override
    public void setWeight(double weight) {
        this.weight = weight;
    }

    public static void reset() {
        currentVertexId = 0;
    }

    @Override
    public int compareTo(Vertex that) {
        double diff = this.weight - that.weight;
        if (diff > 0) {
            return 1;
        } else if (diff < 0) {
            return -1;
        }

        return 0;
    }

    @Override
    public String toString() {
        return "V<" + id + ">";
    }
}
